package com.liry.mybatis.datascope.model;

import com.liry.mybatis.datascope.annotation.DataColumn;
import com.liry.mybatis.datascope.annotation.DataScope;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.stream.Collectors;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 数据权限属性
 *
 * @author ALI
 * @since 2022/9/13
 */
@Data
@EqualsAndHashCode
public class DataScopeProperty {

    /**
     * 类业务型/数据类型
     */
    private String type;

    /**
     * 字段列属性
     */
    private Collection<DataColumnProperty> columns;

    /**
     * 忽略
     */
    private boolean ignore;

    public DataScopeProperty() {
    }

    public DataScopeProperty(DataColumnProperty columnProperty) {
        this.columns = Collections.singletonList(columnProperty);
    }

    public DataScopeProperty(DataScope var1) {
        this.setColumns(var1.value());
        this.ignore = var1.ignore();
    }

    public void setColumns(DataColumn[] data) {
        if (null != data && data.length > 0) {
            this.columns = Arrays.stream(data).map(DataColumnProperty::from).collect(Collectors.toSet());
        }
    }

    public void setColumns(Collection<DataColumnProperty> dataColumnProperties) {
        this.columns = dataColumnProperties;
    }

}
